import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { CommonService } from 'src/app/service/common/common.service';
import { FeeEnquiryService } from 'src/app/service/fee-enquiry/fee-enquiry.service';
import { MessageService } from 'src/app/service/message.service';
import { UserBindService } from 'src/app/service/user-bind.service';

@Component({
  selector: 'app-query',
  templateUrl: './query.component.html',
  styleUrls: ['./query.component.scss']
})
export class QueryComponent implements OnInit {

  constructor(
    private feeEnquiry: FeeEnquiryService,
    private message: MessageService,
    private userBind: UserBindService,
    private router: Router,
    private route: ActivatedRoute,
    private common: CommonService
  ) { }

  pageType: any = ''
  pageTypeEnum: any = ['all', 'un']
  ngOnInit(): void {
    this.common.setRightInfoVisible(false)
    this.getPageType()

    
    this.getBindPage()
  }
  getPageType(){
    this.route.paramMap.subscribe(res => {
      if(this.pageTypeEnum.indexOf(res.get('type')) > -1){
        this.pageType = res.get('type')
      }else{
        this.pageType = 'all'
      }
    })
  }

  cols = {
    'usageCode': '用户编号',
    'name': '户名',
    'address': '用水地址',
    '操作': '操作'
  }
  data = []
  dataLoading = false
  total = 0
  pageSize = 10
  pageNumber = 1
  getBindPage(){
    this.dataLoading = true
    this.data = []
    this.userBind._getBindPage(this.pageNumber, this.pageSize).subscribe({
      next: res => {
        if(res && res.resultList){
          this.data = res.resultList
          this.total = res.totalNumber
        }
        this.dataLoading = false
      },
      error: error => {
        this.message.error('查询数据错误, 请稍后再试')
        this.dataLoading = false
      }
    })
  }

  feeBill(data: any){
    this.router.navigate(['/fee-enquiry/fee-bill'], { queryParams: {
      usageCode: data.usageCode,
      address: data.address,
      name: data.name
    } })
  }
  oweFee(data: any){
    this.router.navigate(['/fee-enquiry/owe-fee'], { queryParams: {
      usageCode: data.usageCode,
      address: data.address,
      name: data.name
    } })
  }

}
